//console.log("Ⓜ️ MKP yelp reviews, before window onload[script 1] running... "); if (window.mkpYelpScriptValidation != "running") { window.mkpYelpScriptValidation = "running"; window.runScriptYelpReviews = function () { //*** Global Variables - Start */ // main endpoints const cdnBaseUrl = "https://mkp-prod.nyc3.cdn.digitaloceanspaces.com/yelp-reviews"; const backendUrl = "https://us-east1-yelp-reviews-wix.cloudfunctions.net"; const appId = "04e6ed92-3bb1-45f1-9503-9cdd41c62ad9"; const instanceId = document .getElementById("mkp_yelp_reviews_script") .src.split("instance_id=")[1]; const vueScriptUrl = cdnBaseUrl + "/vue_widget/app.js"; // should placed in 'vue_widget/' directory const MKPGlobalVars = { cdnUrl: cdnBaseUrl, appId: appId, backendUrl: backendUrl, instanceId: instanceId, }; var MKPAfHttpClient = function () { this.get = function (aUrl, aCallback) { var anHttpRequest = new XMLHttpRequest(); anHttpRequest.onreadystatechange = function () { if (anHttpRequest.readyState == 4 && anHttpRequest.status == 200) aCallback(anHttpRequest.responseText); }; anHttpRequest.open("GET", aUrl, true); anHttpRequest.send(null); }; }; // Reviews data let filteredReviews = []; let reviewsStatistics = { reviews_count: 0, star_count: 0, overall_rating: "0.0", }; let filterOptions = { review_filter: "all", widget_flow: "show-both", open_behavior: "click", }; let widgetData = [ { name: "Review Widget", id: "review-widget", version: "main", minWidth: 300, maxWidth: 1000, elements: { xxs: [ { widgetName: "review-widget", displayName: "Widget container", styles: { L_Bg_Padding: { top: 0, left: 0, bottom: 0, right: 0, }, D_Bg_PrimaryColor: "rgba(250, 250, 250, 1)", D_Bg_Enable_Overlay: false, L_MinHeight: 200, position_Left: "unset", D_Bg_Ov_PrimaryColor: "rgba(0, 0, 0, 0.2)", D_Bg_SecondaryColor: "rgb(255, 255, 255)", position_Right: 20, L_Bg_MobilePadding: { top: 0, left: 0, bottom: 0, right: 0, }, L_ElementGap: 0, L_MaxHeight: 490, position_Bottom: 12, ani_Type: "fade", D_Bg_Blur: 0, position_Top: "unset", D_Bg_Ov_SecondaryColor: "rgba(0, 0, 0, 0.5)", D_Bg_BdrWidth: 1, D_Bg_Ov_Blur: 0, L_Bg_CRadius: 4, D_Bg_BdrColor: "#e5e5e5", D_Bg_Ov_Enable_Gradient: false, position: "right-bottom", D_Bg_Enable_Gradient: false, L_MaxWidth: 450, }, id: "container", type: "widget", }, { displayName: "Close button", styles: { D_Btn_SecondaryColor: "rgb(255, 255, 255)", D_Btn_BdrColor: "#CF7C1B", D_Btn_Enable_Gradient: false, L_Btn_Radius: 24, D_Btn_IconColor: "rgb(0, 0, 0)", L_Btn_Size: 3, D_Btn_BdrWidth: 0, D_Btn_PrimaryColor: "rgba(255, 255, 255, 0.4)", }, id: "cb_1", type: "close-button", }, { iconName: "builder/icon-element-image", displayName: "Review badge", moved: false, h: 6, description: "HTML tag", i: "1", label: "Review badge", type: "review_badge", bdg_text_afterReviewCount: "REVIEWS", w: 4, x: 0, y: 0, styles: { D_Bdg_Enable_Gradient: false, D_Label_TextColor: "#000000", D_Bdg_SecondaryColor: "rgb(255, 255, 255)", L_Bdg_Template: "bdg_3", D_Bdg_BdrColor: "#e5e5e5", D_Bdg_IconFB_Color: "rgba(0, 0, 0, 1)", D_TextColor: "rgba(0, 0, 0, 1)", D_Label_FontSize: 18, L_Bdg_IconStr_Gap: 4, D_Label_Font_Formats: [], D_Label_TextFont: "Poppins", D_Bdg_IconStrOff_Color: "rgba(0, 0, 0, 0.2)", D_FontSize: 12, L_Bdg_IconStr_Size: 20, C_Bdg_Enable_PageURL: false, D_Bdg_LinkColor: "#000000", L_Bdg_ElementGap: 0, D_BdgStars_Color: "#FF1A1A", D_Bdg_BdrWidth: 1, D_ColorScheme: "color_1", D_Bdg_IconStrOn_Color: "#FF1A1A", D_Font_Formats: [], D_Bdg_PrimaryColor: "rgb(255, 255, 255)", L_Bdg_Radius: 0, L_Bdg_Padding: { top: 6, left: 12, bottom: 6, right: 12, }, D_TextFont: "Poppins", L_Bdg_Icon_Size: 42, }, id: "review_badge_0", reviews_overall: { overall_rating: "5", star_count: "158", reviews_count: "100", }, }, { iconName: "builder/icon-element-image", displayName: "Review cards", moved: false, h: 30, description: "HTML tag", i: "2", label: "Review cards", type: "review_cards", reviews: [ { reviewer_name: "Christina Paradun", rating: 5, created_at: "2023-05-04T14:39:08+0000", reviewer_avatar: "", content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Aperiam non pariatur debitis officiis eum sed, ipsum esse suscipit vero fuga quia recusandae doloribus consequuntur sint illo minus sit temporibus nulla.", }, ], w: 6, x: 0, y: 6, styles: { L_Crd_Template: "Crd_1", D_Crd_Title_TextColor: "rgba(0, 0, 0, 1)", D_Bg_PrimaryColor: "rgb(255, 255, 255)", D_Crd_PrimaryColor: "rgb(255, 255, 255)", D_Crd_BdrColor: "#e5e5e5", D_Label_TextColor: "rgba(0, 0, 0, 0.9)", D_Bg_SecondaryColor: "rgb(255, 255, 255)", D_Crd_IconFB_Color: "rgba(0, 0, 0, 1)", L_Crd_UserAvatar_Size: 56, D_Crd_BdrWidth: 1, L_Crd_IconStr_Size: 20, D_Crd_IconStrOn_Color: "#FB503B", D_Crd_IconStrOff_Color: "#ababab", D_Bg_Blur: 0, D_TextColor: "rgba(0, 0, 0, 0.9)", D_Bg_BdrWidth: 0, D_Bg_BdrColor: "#20455E", L_Bg_Align: "left", D_Label_FontSize: 16, D_Bg_Enable_Gradient: false, L_Bg_Padding: { top: 12, left: 24, bottom: 12, right: 24, }, L_Crd_Padding: { top: 24, left: 12, bottom: 24, right: 12, }, D_Label_Font_Formats: [], D_Label_TextFont: "Poppins", D_FontSize: 12, L_Crd_Radius: 0, L_Bg_MobilePadding: { top: 12, left: 0, bottom: 12, right: 0, }, L_ElementGap: 0, L_Crd_ElementGap: 8, D_ColorScheme: "color_1", L_Bg_CRadius: 0, D_Font_Formats: [], D_Crd_Enable_Gradient: false, D_Crd_SecondaryColor: "rgb(220, 205, 235)", L_Crd_IconStr_Gap: 4, D_TextFont: "Poppins", D_Crd_ShowMoreColor: "#FB503B", }, id: "review_cards_0", }, ], lg: [ { widgetName: "review-widget", displayName: "Widget container", styles: { L_Bg_Padding: { top: 0, left: 0, bottom: 0, right: 0, }, D_Bg_PrimaryColor: "rgba(250, 250, 250, 1)", D_Bg_Enable_Overlay: false, L_MinHeight: 200, position_Left: "unset", D_Bg_Ov_PrimaryColor: "rgba(0, 0, 0, 0.2)", D_Bg_SecondaryColor: "rgb(255, 255, 255)", position_Right: 20, L_Bg_MobilePadding: { top: 0, left: 0, bottom: 0, right: 0, }, L_ElementGap: 0, L_MaxHeight: 490, position_Bottom: 12, ani_Type: "fade", D_Bg_Blur: 0, position_Top: "unset", D_Bg_Ov_SecondaryColor: "rgba(0, 0, 0, 0.5)", D_Bg_BdrWidth: 1, D_Bg_Ov_Blur: 0, L_Bg_CRadius: 4, D_Bg_BdrColor: "#e5e5e5", D_Bg_Ov_Enable_Gradient: false, position: "right-bottom", D_Bg_Enable_Gradient: false, L_MaxWidth: 450, }, id: "container", type: "widget", }, { displayName: "Close button", styles: { D_Btn_SecondaryColor: "rgb(255, 255, 255)", D_Btn_BdrColor: "#CF7C1B", D_Btn_Enable_Gradient: false, L_Btn_Radius: 24, D_Btn_IconColor: "rgb(0, 0, 0)", L_Btn_Size: 3, D_Btn_BdrWidth: 0, D_Btn_PrimaryColor: "rgba(255, 255, 255, 0.4)", }, id: "cb_1", type: "close-button", }, { iconName: "builder/icon-element-image", displayName: "Review badge", moved: false, h: 6, description: "HTML tag", i: "1", label: "Review badge", type: "review_badge", bdg_text_afterReviewCount: "REVIEWS", w: 4, x: 0, y: 0, styles: { D_Bdg_Enable_Gradient: false, D_Label_TextColor: "#000000", D_Bdg_SecondaryColor: "rgb(255, 255, 255)", L_Bdg_Template: "bdg_3", D_Bdg_BdrColor: "#e5e5e5", D_Bdg_IconFB_Color: "rgba(0, 0, 0, 1)", D_TextColor: "rgba(0, 0, 0, 1)", D_Label_FontSize: 18, L_Bdg_IconStr_Gap: 4, D_Label_Font_Formats: [], D_Label_TextFont: "Poppins", D_Bdg_IconStrOff_Color: "rgba(0, 0, 0, 0.2)", D_FontSize: 12, L_Bdg_IconStr_Size: 20, C_Bdg_Enable_PageURL: false, D_Bdg_LinkColor: "#000000", L_Bdg_ElementGap: 0, D_BdgStars_Color: "#FF1A1A", D_Bdg_BdrWidth: 1, D_ColorScheme: "color_1", D_Bdg_IconStrOn_Color: "#FF1A1A", D_Font_Formats: [], D_Bdg_PrimaryColor: "rgb(255, 255, 255)", L_Bdg_Radius: 0, L_Bdg_Padding: { top: 6, left: 12, bottom: 6, right: 12, }, D_TextFont: "Poppins", L_Bdg_Icon_Size: 42, }, id: "review_badge_0", reviews_overall: { overall_rating: "5", star_count: "158", reviews_count: "100", }, }, { iconName: "builder/icon-element-image", displayName: "Review cards", moved: false, h: 30, description: "HTML tag", i: "2", label: "Review cards", type: "review_cards", reviews: [ { reviewer_name: "Christina Paradun", rating: 5, created_at: "2023-05-04T14:39:08+0000", reviewer_avatar: "", content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Aperiam non pariatur debitis officiis eum sed, ipsum esse suscipit vero fuga quia recusandae doloribus consequuntur sint illo minus sit temporibus nulla.", }, ], w: 6, x: 0, y: 6, styles: { L_Crd_Template: "Crd_1", D_Crd_Title_TextColor: "rgba(0, 0, 0, 1)", D_Bg_PrimaryColor: "rgb(255, 255, 255)", D_Crd_PrimaryColor: "rgb(255, 255, 255)", D_Crd_BdrColor: "#e5e5e5", D_Label_TextColor: "rgba(0, 0, 0, 0.9)", D_Bg_SecondaryColor: "rgb(255, 255, 255)", D_Crd_IconFB_Color: "rgba(0, 0, 0, 1)", L_Crd_UserAvatar_Size: 56, D_Crd_BdrWidth: 1, L_Crd_IconStr_Size: 20, D_Crd_IconStrOn_Color: "#FB503B", D_Crd_IconStrOff_Color: "#ababab", D_Bg_Blur: 0, D_TextColor: "rgba(0, 0, 0, 0.9)", D_Bg_BdrWidth: 0, D_Bg_BdrColor: "#20455E", L_Bg_Align: "left", D_Label_FontSize: 16, D_Bg_Enable_Gradient: false, L_Bg_Padding: { top: 12, left: 24, bottom: 12, right: 24, }, L_Crd_Padding: { top: 24, left: 12, bottom: 24, right: 12, }, D_Label_Font_Formats: [], D_Label_TextFont: "Poppins", D_FontSize: 12, L_Crd_Radius: 0, L_Bg_MobilePadding: { top: 12, left: 0, bottom: 12, right: 0, }, L_ElementGap: 0, L_Crd_ElementGap: 8, D_ColorScheme: "color_1", L_Bg_CRadius: 0, D_Font_Formats: [], D_Crd_Enable_Gradient: false, D_Crd_SecondaryColor: "rgb(220, 205, 235)", L_Crd_IconStr_Gap: 4, D_TextFont: "Poppins", D_Crd_ShowMoreColor: "#FB503B", }, id: "review_cards_0", }, ], }, }, { name: "Review Widget", id: "review-widget_teaser", version: "teaser", minWidth: 200, maxWidth: 600, elements: { xxs: [ { widgetName: "review-widget_teaser", displayName: "Widget container", styles: { L_Bg_Padding: { top: 0, left: 0, bottom: 0, right: 0, }, D_Bg_PrimaryColor: "rgba(255, 255, 255, 0)", L_MinHeight: 40, ani_ShowAfter: 1.5, position_Left: "unset", D_Bg_SecondaryColor: "rgba(46, 129, 255, 1)", position_Right: 20, L_Bg_MobilePadding: { top: 0, left: 0, bottom: 0, right: 0, }, L_ElementGap: 0, L_MaxHeight: 300, position_Bottom: 12, ani_Type: "fade", D_Bg_Blur: 0, position_Top: "unset", D_Bg_BdrWidth: 0, L_Bg_CRadius: 6, D_Bg_BdrColor: "rgb(255, 255, 255)", position: "right-bottom", D_Bg_Enable_Gradient: false, L_MaxWidth: 320, }, id: "container", type: "widget", }, { iconName: "builder/icon-element-image", displayName: "Review badge", moved: false, h: 6, description: "HTML tag", i: "1", label: "Review badge", type: "review_badge", bdg_text_afterReviewCount: "REVIEWS", w: 4, x: 0, y: 0, styles: { D_Bdg_Enable_Gradient: false, D_Label_TextColor: "#000000", D_Bdg_SecondaryColor: "rgb(255, 255, 255)", L_Bdg_Template: "bdg_3", D_Bdg_BdrColor: "#e5e5e5", D_Bdg_IconFB_Color: "rgba(0, 0, 0, 1)", D_TextColor: "rgba(0, 0, 0, 1)", D_Label_FontSize: 18, L_Bdg_IconStr_Gap: 4, D_Label_Font_Formats: [], D_Label_TextFont: "Poppins", D_Bdg_IconStrOff_Color: "rgba(0, 0, 0, 0.2)", D_FontSize: 12, L_Bdg_IconStr_Size: 20, D_Bdg_LinkColor: "#000000", L_Bdg_ElementGap: 0, D_BdgStars_Color: "#FF1A1A", D_Bdg_BdrWidth: 1, D_ColorScheme: "color_1", D_Bdg_IconStrOn_Color: "#FF1A1A", D_Font_Formats: [], D_Bdg_PrimaryColor: "rgb(255, 255, 255)", L_Bdg_Radius: 0, L_Bdg_Padding: { top: 6, left: 12, bottom: 6, right: 12, }, D_TextFont: "Poppins", L_Bdg_Icon_Size: 42, }, id: "review_badge_0", reviews_overall: { overall_rating: "5", star_count: "158", reviews_count: "100", }, }, ], lg: [ { widgetName: "review-widget_teaser", displayName: "Widget container", styles: { L_Bg_Padding: { top: 0, left: 0, bottom: 0, right: 0, }, D_Bg_PrimaryColor: "rgba(255, 255, 255, 0)", L_MinHeight: 40, ani_ShowAfter: 1.5, position_Left: "unset", D_Bg_SecondaryColor: "rgba(46, 129, 255, 1)", position_Right: 20, L_Bg_MobilePadding: { top: 0, left: 0, bottom: 0, right: 0, }, L_ElementGap: 0, L_MaxHeight: 300, position_Bottom: 12, ani_Type: "fade", D_Bg_Blur: 0, position_Top: "unset", D_Bg_BdrWidth: 0, L_Bg_CRadius: 6, D_Bg_BdrColor: "rgb(255, 255, 255)", position: "right-bottom", D_Bg_Enable_Gradient: false, L_MaxWidth: 320, }, id: "container", type: "widget", }, { iconName: "builder/icon-element-image", displayName: "Review badge", moved: false, h: 6, description: "HTML tag", i: "1", label: "Review badge", type: "review_badge", bdg_text_afterReviewCount: "REVIEWS", w: 4, x: 0, y: 0, styles: { D_Bdg_Enable_Gradient: false, D_Label_TextColor: "#000000", D_Bdg_SecondaryColor: "rgb(255, 255, 255)", L_Bdg_Template: "bdg_3", D_Bdg_BdrColor: "#e5e5e5", D_Bdg_IconFB_Color: "rgba(0, 0, 0, 1)", D_TextColor: "rgba(0, 0, 0, 1)", D_Label_FontSize: 18, L_Bdg_IconStr_Gap: 4, D_Label_Font_Formats: [], D_Label_TextFont: "Poppins", D_Bdg_IconStrOff_Color: "rgba(0, 0, 0, 0.2)", D_FontSize: 12, L_Bdg_IconStr_Size: 20, D_Bdg_LinkColor: "#000000", L_Bdg_ElementGap: 0, D_BdgStars_Color: "#FF1A1A", D_Bdg_BdrWidth: 1, D_ColorScheme: "color_1", D_Bdg_IconStrOn_Color: "#FF1A1A", D_Font_Formats: [], D_Bdg_PrimaryColor: "rgb(255, 255, 255)", L_Bdg_Radius: 0, L_Bdg_Padding: { top: 6, left: 12, bottom: 6, right: 12, }, D_TextFont: "Poppins", L_Bdg_Icon_Size: 42, }, id: "review_badge_0", reviews_overall: { overall_rating: "5", star_count: "158", reviews_count: "100", }, }, ], }, }, ]; let widgetVisibility = { visibility_status: true, visibility_option: "home-only", }; let subscriptionPlan = "Free"; let connectedPage = { id: "", name: "", url: "", listingName: "", profilePictureURL: "", }; // Permission keys let isPreviewMode = false; /** flag use for hide widget in dashboard app web previews */ let isWidgetDataAvailable = true; let isHomePage = true; //*** Global Variables - End */ // Run functions bindGlobalVariables(); bindVueWidget(); mkpFetchReviewsData(); // checkAndAddWidgets(); //*** Functions - Start */ function bindGlobalVariables() { //Add main/global variables into head const MKPGlobalVarsScript = document.createElement("script"); MKPGlobalVarsScript.setAttribute( "MkpFBReviewsGlobalVars", JSON.stringify(MKPGlobalVars) ); MKPGlobalVarsScript.id = "MKP-FB-REVIEWS-GLOBAL-VARS"; document.head.appendChild(MKPGlobalVarsScript); } function bindVueWidget() { //Add vue widget .js and .css file into the head const MKPImportedVueComps = document.createElement("script"); MKPImportedVueComps.src = vueScriptUrl; document.head.appendChild(MKPImportedVueComps); } function mkpRegisterListener() { window.wixDevelopersAnalytics.register( MKPGlobalVars.appId, (eventName, eventParams) => { switch (eventName) { case "PageView": const pagePath = eventParams.pagePath; isHomePage = pagePath === "/"; checkAndAddWidgets(); break; case "ViewContent": //isHomePage = pagePath === "/"; //checkAndAddWidgets(); break; } } ); } function mkpFetchReviewsData() { const backendUrl = MKPGlobalVars.backendUrl; const instance_id = `instance_id=${MKPGlobalVars.instanceId}`; const getReviewsDataUrl = `${backendUrl}/getMemberReviewsData?${instance_id}`; const mkpGetClient = new MKPAfHttpClient(); mkpGetClient.get(getReviewsDataUrl, function (res) { const reviewsData = JSON.parse(res); filteredReviews = reviewsData.filtered_reviews || filteredReviews; reviewsStatistics = reviewsData.reviews_statistics || reviewsStatistics; filterOptions = reviewsData.filter_options || filterOptions; widgetVisibility = reviewsData.widget_visibility || widgetVisibility; subscriptionPlan = reviewsData.subscription_plan || subscriptionPlan; connectedPage = reviewsData.airbnb_page || connectedPage; const fb_widgetData = reviewsData.widget_data; isWidgetDataAvailable = Object.keys(widgetData).length > 0; if (isWidgetDataAvailable) widgetData = fb_widgetData; //console.log("Ⓜ️ ~ reviewsData:", reviewsData); //console.log("Ⓜ️ ~ widgetData:", widgetData); checkAndAddWidgets(); }); } function checkAndAddWidgets() { mkpRemoveWidget(); const isWidgetActive = widgetVisibility.visibility_status == true; const visibleOnlyInHomePage = widgetVisibility.visibility_option === "home-only"; const isFreePlanUser = subscriptionPlan === "Free"; if (!isWidgetActive || !isWidgetDataAvailable || isPreviewMode) { return; } if ((isFreePlanUser || visibleOnlyInHomePage) && isHomePage) { mkpShowReviewsWidget(); } if (!isFreePlanUser && !visibleOnlyInHomePage) { mkpShowReviewsWidget(); } if ((isFreePlanUser || visibleOnlyInHomePage) && !isHomePage) { mkpRemoveWidget(); } } function mkpShowReviewsWidget() { let reviewsWidget = document.createElement("mkp-yelp-reviews"); reviewsWidget.setAttribute("reviewdata", JSON.stringify(filteredReviews)); reviewsWidget.setAttribute( "reviewsstatistics", JSON.stringify(reviewsStatistics) ); reviewsWidget.setAttribute("filterreviews", JSON.stringify(filterOptions)); reviewsWidget.setAttribute("connectedpage", JSON.stringify(connectedPage)); const mainModalStyleData = JSON.stringify(widgetData[0]); const teaserStyleData = JSON.stringify(widgetData[1]); reviewsWidget.setAttribute("mainstyledata", mainModalStyleData); reviewsWidget.setAttribute("teaserstyledata", teaserStyleData); document.body.appendChild(reviewsWidget); } function mkpRemoveWidget() { let reviewsWidget = document.querySelector("mkp-yelp-reviews"); if (reviewsWidget) reviewsWidget.remove(); } function previewScreenCheckEvent(event) { // remove widget in preview mode if (event.data.action === "mkpHideWidget") { // console.log("Ⓜ️ This is preview screen: ", event.data); isPreviewMode = true; mkpRemoveWidget(); } } //*** Functions - End */ // check is widget page in the preview mode window.addEventListener("message", previewScreenCheckEvent); // Remove the event listener after 15 seconds setTimeout(() => { window.removeEventListener("message", previewScreenCheckEvent); }, 16000); window.wixDevelopersAnalytics ? mkpRegisterListener() : window.addEventListener( "wixDevelopersAnalyticsReady", mkpRegisterListener ); }; window.runScriptYelpReviews(); }